package io.github.cchenxi.crpc.core.provider;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.core.annotation.Order;

import io.github.cchenxi.crpc.core.api.RegistryCenter;
import io.github.cchenxi.crpc.core.registry.ZkRegistryCenter;

/**
 * 提供者配置
 * Date: 2024-03-07
 *
 * @author chenxi
 */
@Configuration
public class ProviderConfig {
    @Bean
    ProviderBootstrap providerBootstrap() {
        return new ProviderBootstrap();
    }

    @Bean
    ProviderInvoker providerInvoker(@Autowired ProviderBootstrap providerBootstrap) {
        return new ProviderInvoker(providerBootstrap);
    }

    @Bean
    @Order(Integer.MIN_VALUE)
    public ApplicationRunner ProviderRunner(@Autowired ProviderBootstrap providerBootstrap) {
        return x-> {
            System.out.println("ProviderBootstrap starting...");
            providerBootstrap.start();
            System.out.println("ProviderBootstrap started...");
        };
    }

    @Bean
    RegistryCenter providerRegisterCenter() {
        return new ZkRegistryCenter();
    }
}
